class MobileAreaController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ mobileAreaInstanceList: MobileArea.list( params ) ]
    }

    def show = {
        def mobileAreaInstance = MobileArea.get( params.id )

        if(!mobileAreaInstance) {
            flash.message = "MobileArea not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ mobileAreaInstance : mobileAreaInstance ] }
    }

    def delete = {
        def mobileAreaInstance = MobileArea.get( params.id )
        if(mobileAreaInstance) {
            mobileAreaInstance.delete()
            flash.message = "号码段 ${params.id} 已被删除"
            redirect(action:list)
        }
        else {
            flash.message = "MobileArea not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def mobileAreaInstance = MobileArea.get( params.id )

        if(!mobileAreaInstance) {
            flash.message = "MobileArea not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ mobileAreaInstance : mobileAreaInstance ]
        }
    }

    def update = {
        def mobileAreaInstance = MobileArea.get( params.id )
        if(mobileAreaInstance) {
            mobileAreaInstance.properties = params
            if(!mobileAreaInstance.hasErrors() && mobileAreaInstance.save()) {
                flash.message = "号码段 ${params.id} 已经更新"
                redirect(action:show,id:mobileAreaInstance.id)
            }
            else {
                render(view:'edit',model:[mobileAreaInstance:mobileAreaInstance])
            }
        }
        else {
            flash.message = "MobileArea not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def mobileAreaInstance = new MobileArea()
        mobileAreaInstance.properties = params
        return ['mobileAreaInstance':mobileAreaInstance]
    }

    def save = {
        def mobileAreaInstance = new MobileArea(params)
        if(!mobileAreaInstance.hasErrors() && mobileAreaInstance.save()) {
            flash.message = "号码段 ${mobileAreaInstance.id} 已创建"
            redirect(action:show,id:mobileAreaInstance.id)
        }
        else {
            render(view:'create',model:[mobileAreaInstance:mobileAreaInstance])
        }
    }
}
